<?php defined('BASEPATH') OR exit('No direct script access allowed');
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);

class Role_module extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('role_module/role_module_model','rmm');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] = TRUE;
		$this->header['groups'] = $this->rmm->get_groups();
		$this->header['source_bot'] = array(
			script_tag(site_url('role_module/themescript/moment.js')),
			script_tag(site_url('role_module/themescript/datepicker/js/bootstrap-datepicker.js')),
			
			script_tag(site_url('role_module/themescript/app/role_module.js'))
		);
	}

	function index()
	{

		/*$group = $this->session->userdata('ba_groups');
		echo "<pre>";print_r($group[0]); exit();*/
		$this->init_header();
		$this->header['nav'] = 'settings';
		$this->header['pagetitle'] = 'Role Module';
		$this->view('role_module/role_module_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->rmm->get_all($params);
		print(json_encode($result));
	}

	function save_data()
	{
		$post = $this->input->post();
		if (empty($post['role_id'])) {
			unset($post['role_id']);
			$this->rmm->add($post);
		} else {
			$this->rmm->edit($post, array(
				'role_id' => $post['role_id']
			));
		}

		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function delete_data()
	{
		$post = $this->input->post();
		$this->rmm->delete(array('role_id' => $post['role_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

}

/* End of file role_module.php */
/* Location: ./applications/module_admin/role_module/controllers/role_module.php */